package com.rakuten.api.mule.transformers;

import org.mule.api.MuleMessage;
import org.mule.api.transformer.TransformerException;
import org.mule.transformer.AbstractMessageTransformer;

import com.rakuten.api.mule.model.rms.Product;

public class GetProductInfo extends AbstractMessageTransformer {

	public GetProductInfo() {
		super();
	}

	@Override
	public Object transformMessage(MuleMessage message, String outputEncoding)
			throws TransformerException {
		// Set original payload to session variable

		try {
			Product productResponse;
			GetProductResponse getProductResponse = message
					.getPayload(GetProductResponse.class);
			productResponse = getProductResponse.getProduct();
			if (getProductResponse.getStatus().compareTo("200") == 0) {
				message.setPayload(productResponse);
			} else {
				message.setPayload(getProductResponse.getError());
			}

			return message;
		} catch (Exception ex) {
			throw new TransformerException(this, ex);
		}
	}
	/**
	 * TODO Temporary implementation. implements MongoDB version.
	 */

}
